home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / ZPATH.C < prev    next >
C/C++ Source or Header  |  1991-08-01  |  5KB  |  201 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* zpath.c */
  21. /* Path operators for GhostScript */
  22. #include "math_.h"
  23. #include "ghost.h"
  24. #include "errors.h"
  25. #include "oper.h"
  26. #include "gsmatrix.h"
  27. #include "gspath.h"
  28. #include "state.h"
  29. #include "store.h"
  30.  
  31. /* Forward references */
  32. private int near common_to(P2(os_ptr,
  33.   int (*)(P3(gs_state *, floatp, floatp))));
  34. private int near common_arc(P2(os_ptr,
  35.   int (*)(P6(gs_state *, floatp, floatp, floatp, floatp, floatp))));
  36. private int near common_arct(P2(os_ptr, float *));
  37. private int near common_curve(P2(os_ptr,
  38.   int (*)(P7(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp))));
  39.  
  40. /* Imported from zmath.c */
  41. extern double degrees_to_radians, radians_to_degrees;
  42.  
  43. /* newpath */
  44. int
  45. znewpath(register os_ptr op)
  46. {    return gs_newpath(igs);
  47. }
  48.  
  49. /* currentpoint */
  50. int
  51. zcurrentpoint(register os_ptr op)
  52. {    gs_point pt;
  53.     int code = gs_currentpoint(igs, &pt);
  54.     if ( code < 0 ) return code;
  55.     push(2);
  56.     make_real(op - 1, pt.x);
  57.     make_real(op, pt.y);
  58.     return 0;
  59. }
  60.  
  61. /* moveto */
  62. int
  63. zmoveto(os_ptr op)
  64. {    return common_to(op, gs_moveto);
  65. }
  66.  
  67. /* rmoveto */
  68. int
  69. zrmoveto(os_ptr op)
  70. {    return common_to(op, gs_rmoveto);
  71. }
  72.  
  73. /* lineto */
  74. int
  75. zlineto(os_ptr op)
  76. {    return common_to(op, gs_lineto);
  77. }
  78.  
  79. /* rlineto */
  80. int
  81. zrlineto(os_ptr op)
  82. {    return common_to(op, gs_rlineto);
  83. }
  84.  
  85. /* Common code for [r](move/line)to */
  86. private int near
  87. common_to(os_ptr op, int (*add_proc)(P3(gs_state *, floatp, floatp)))
  88. {    float opxy[2];
  89.     int code;
  90.     if (    (code = num_params(op, 2, opxy)) < 0 ||
  91.         (code = (*add_proc)(igs, opxy[0], opxy[1])) < 0
  92.        ) return code;
  93.     pop(2);
  94.     return 0;
  95. }
  96.  
  97. /* arc */
  98. int
  99. zarc(os_ptr op)
  100. {    return common_arc(op, gs_arc);
  101. }
  102.  
  103. /* arcn */
  104. int
  105. zarcn(os_ptr op)
  106. {    return common_arc(op, gs_arcn);
  107. }
  108.  
  109. /* Common code for arc[n] */
  110. private int near
  111. common_arc(os_ptr op,
  112.   int (*aproc)(P6(gs_state *, floatp, floatp, floatp, floatp, floatp)))
  113. {    float xyra[5];            /* x, y, r, ang1, ang2 */
  114.     int code;
  115.     if ( (code = num_params(op, 5, xyra)) < 0 ) return code;
  116.     code = (*aproc)(igs, xyra[0], xyra[1], xyra[2], xyra[3], xyra[4]);
  117.     if ( code >= 0 ) pop(5);
  118.     return code;
  119. }
  120.  
  121. /* arct */
  122. int
  123. zarct(register os_ptr op)
  124. {    int code = common_arct(op, (float *)0);
  125.     if ( code < 0 ) return code;
  126.     pop(5);
  127.     return 0;
  128. }
  129.  
  130. /* arcto */
  131. int
  132. zarcto(register os_ptr op)
  133. {    float tanxy[4];            /* xt1, yt1, xt2, yt2 */
  134.     int code = common_arct(op, tanxy);
  135.     if ( code < 0 ) return code;
  136.     make_real(op - 4, tanxy[0]);
  137.     make_real(op - 3, tanxy[1]);
  138.     make_real(op - 2, tanxy[2]);
  139.     make_real(op - 1, tanxy[3]);
  140.     pop(1);
  141.     return 0;
  142. }
  143.  
  144. /* Common code for arct[o] */
  145. private int near
  146. common_arct(os_ptr op, float *tanxy)
  147. {    float args[5];            /* x1, y1, x2, y2, r */
  148.     int code;
  149.     if ( (code = num_params(op, 5, args)) < 0 ) return code;
  150.     return gs_arcto(igs, args[0], args[1], args[2], args[3], args[4], tanxy);
  151. }
  152.  
  153. /* curveto */
  154. int
  155. zcurveto(register os_ptr op)
  156. {    return common_curve(op, gs_curveto);
  157. }
  158.  
  159. /* rcurveto */
  160. int
  161. zrcurveto(register os_ptr op)
  162. {    return common_curve(op, gs_rcurveto);
  163. }
  164.  
  165. /* Common code for [r]curveto */
  166. private int near
  167. common_curve(os_ptr op,
  168.   int (*add_proc)(P7(gs_state *, floatp, floatp, floatp, floatp, floatp, floatp)))
  169. {    float opxy[6];
  170.     int code;
  171.     if ( (code = num_params(op, 6, opxy)) < 0 ) return code;
  172.     code = (*add_proc)(igs, opxy[0], opxy[1], opxy[2], opxy[3], opxy[4], opxy[5]);
  173.     if ( code >= 0 ) pop(6);
  174.     return code;
  175. }
  176.  
  177. /* closepath */
  178. int
  179. zclosepath(register os_ptr op)
  180. {    return gs_closepath(igs);
  181. }
  182.  
  183. /* ------ Initialization procedure ------ */
  184.  
  185. op_def zpath_op_defs[] = {
  186.     {"5arc", zarc},
  187.     {"5arcn", zarcn},
  188.     {"5arct", zarct},
  189.     {"5arcto", zarcto},
  190.     {"0closepath", zclosepath},
  191.     {"0currentpoint", zcurrentpoint},
  192.     {"6curveto", zcurveto},
  193.     {"2lineto", zlineto},
  194.     {"2moveto", zmoveto},
  195.     {"0newpath", znewpath},
  196.     {"6rcurveto", zrcurveto},
  197.     {"2rlineto", zrlineto},
  198.     {"2rmoveto", zrmoveto},
  199.     op_def_end(0)
  200. };
  201.